/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2022-06-23 11:36:36
 * @LastEditors: TT
 * @LastEditTime: 2022-07-27 11:07:56
 */

import 'package:flutter/material.dart';
import 'package:hzy_normal_widget/hzy_normal_widget.dart';
import 'package:hzy_template/config/controller/launch_change_c.dart';
import 'package:hzy_template/config/dataconfig/hzy_color_config.dart';
import 'package:hzy_template/config/dataconfig/language_info_config.dart';
import 'package:hzy_template/pages/my/models/my_data.dart';
import 'package:hzy_template/utils/utils_index.dart';

import '../../../components/common_index.dart';
import '../../../config/models/normmal_title_item_model.dart';

class MyLaunchC extends CommonGetXController {
  List<NormalTitleItemModel> list = MyData().configLaunchlistinfo();

  /// 选中下表
  var selectIndex = 0.obs;

  /// 数组长度
  var listleng = MyData().configLaunchlistinfo().length.obs;
  String launchStr = "zh_CN";
  String locahlaunchstr = "zh_CN";

  /// 是否可以点击
  var iscantap = false.obs;

  /// 右上角 按钮背景颜色
  var surebackColor = CommentColorS.coldadada.obs;

  /// 右上角 字体颜色
  var suretitleColor = HzyColorConfig().colplacetextcolor.obs;
  @override
  void onInit() {
    super.onInit();
    launchStr = CommonSpUtil.getLaunchType();
    if (launchStr == "") {
      launchStr = "zh_CN";
    }
    locahlaunchstr = launchStr;
    for (var item in list) {
      if (item.rightmsg == launchStr) {
        selectIndex.value = item.index!;
      }
    }
  }

  /// 切换语言
  void changelaunch() async {

    List list = launchStr.split('_');
    String languageCode = 'zh';
    String countryCode = "CN";
    if (list.length == 2) {
      languageCode = list[0];
      countryCode = list[1];
    }
    var locale = Locale(languageCode, countryCode);
    await Get.updateLocale(locale);
    await CommonSpUtil.saveLauchType(launch: launchStr);
    ///LaunchChangeC.current.changelaunch(launchStr: launchStr);
  }

  void tapItem({required NormalTitleItemModel model}) {
    selectIndex.value = model.index!;
    launchStr = configLaunchStr(launch: model.leftmsg ?? "");

    if (launchStr == locahlaunchstr) {
      iscantap.value = false;
      surebackColor.value = CommentColorS.coldadada;
      suretitleColor.value = HzyColorConfig().colplacetextcolor;
    } else {
      iscantap.value = true;
      surebackColor.value = HzyColorConfig().colthemes;
      suretitleColor.value = CommentColorS.colffffff;
    }
  }

  /// 配置语言
  String configLaunchStr({required String launch}) {
    String launchstr = "zh_CN";
    switch (launch) {
      case "简体中文":
        launchstr = "zh_CN";
        break;
      case "English":
        launchstr = "en_US";
        break;
      default:
    }
    return launchstr;
  }
}
